<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="补发师id" prop="teacherId">-->
<!--        <el-input-->
<!--          v-model="queryParams.teacherId"-->
<!--          placeholder="请输入补发师id"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="选择补发师" prop="teacherId" label-width="100">
        <el-select @change="handleQuery" v-model="queryParams.teacherId" clearable filterable placeholder="请选择">
          <el-option
            v-for="item in hairFixTeacherList"
            :key="item.id"
            :label="item.nickName"
            :value="item.id + ''">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="老师名称" prop="teacherName">
        <el-input
          v-model="queryParams.teacherName"
          placeholder="请输入老师名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入昵称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属军区" prop="theirMilitary">
        <el-select
          v-model="queryParams.theirMilitary"
          placeholder="请选择所属军区"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in belong_military_region"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="所属门店" prop="shopId">
        <el-input
          v-model="queryParams.shopId"
          placeholder="请输入所属门店"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="是否展示在补发师详情中" prop="isShow" label-width="200">
        <el-select
          @change="handleQuery"
          v-model="queryParams.isShow"
          placeholder="是否展示"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in sys_show_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['business:hairTeacherEvaluate:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="Edit"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['business:hairTeacherEvaluate:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:hairTeacherEvaluate:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="Download"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:hairTeacherEvaluate:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="hairTeacherEvaluateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="身份" align="center" prop="orderId">
        <template #default="scope">
          <el-tag effect="dark" type="success" v-if="scope.row.orderId">用户</el-tag>
          <el-tag effect="dark"  v-else>官方</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="老师" align="center" prop="teacherName" />
      <el-table-column label="所属门店" align="center" prop="shopName" />
      <el-table-column label="所属军区" align="center" prop="theirMilitary" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="客户姓名" align="center" prop="nickName" />
      <el-table-column label="手机" align="center" prop="phonenumber" />
<!--      <el-table-column label="用户头像" align="center" prop="avatar">-->
<!--        <template #default="scope">-->
<!--          <template v-if="scope.row.avatar != null">-->
<!--            <template v-for="item in scope.row.avatar.split(',')" :key="item">-->
<!--              <image-preview :src="item" :width="50" :height="50" />-->
<!--            </template>-->
<!--          </template>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="总体评分" align="center" prop="overallScore" />
      <el-table-column label="服务分" align="center" prop="serveScore" />
      <el-table-column label="态度分" align="center" prop="mannerScore" />
      <el-table-column label="效果分" align="center" prop="effectScore" />
      <el-table-column label="评价内容" align="center" prop="content" show-overflow-tooltip/>
<!--      <el-table-column label="是否展示在补发师详情中" align="center" prop="isShow">-->
<!--        <template #default="scope">-->
<!--          <dict-tag :options="sys_show_status" :value="scope.row.isShow"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="是否置顶在补发师列表" align="center" prop="isTop">
        <template #default="scope">
          <el-switch
            v-model="scope.row.isTop"
            active-value="1"
            inactive-value="0"
            @click="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="显示状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="sys_show_hide" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="评价图片" align="center" prop="evaluationPicture">
        <template #default="scope">
          <template v-if="scope.row.evaluationPicture != null">
            <template v-for="item in scope.row.evaluationPicture.split(',')" :key="item">
              <image-preview :src="item" :width="50" :height="50" />
            </template>
          </template>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:hairTeacherEvaluate:edit']">回复</el-button>
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:hairTeacherEvaluate:remove']">删除</el-button>
          </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改补发师评价信息对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body @close="cancel">
      <el-form ref="hairTeacherEvaluateRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属军区" prop="theirMilitary">
          <el-select
            v-model="form.theirMilitary"
            placeholder="请选择所属军区"
            @change="selectTheirMilitary(form.theirMilitary)"
          >
            <el-option
              v-for="dict in belong_military_region"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="门店" prop="shopId">
          <el-select
            clearable
            v-model="form.shopId"
            placeholder="选择门店"
            @change="selectShop(form.shopId)"
          >
            <el-option
              v-for="dict in hairFixShopList"
              :key="dict.id"
              :label="dict.shopName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择补发师" prop="teacherId" label-width="100">
          <el-select v-model="form.teacherId" filterable placeholder="请选择">
            <el-option
              v-for="item in hairFixTeacherList"
              :key="item.id"
              :label="item.nickName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="用户id" prop="userId">-->
<!--          <el-input v-model="form.userId" placeholder="请输入用户id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="昵称" prop="nickName">-->
<!--          <el-input v-model="form.nickName" placeholder="请输入昵称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="用户头像" prop="avatar">-->
<!--          <el-input v-model="form.avatar" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="总体评分" prop="overallScore">-->
<!--          <el-input v-model="form.overallScore" placeholder="请输入总体评分" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="服务分数" prop="serveScore">-->
<!--          <el-input v-model="form.serveScore" placeholder="请输入服务分数" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="态度分数" prop="mannerScore">-->
<!--          <el-input v-model="form.mannerScore" placeholder="请输入态度分数" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="效果分数" prop="effectScore">-->
<!--          <el-input v-model="form.effectScore" placeholder="请输入效果分数" />-->
<!--        </el-form-item>-->
        <el-form-item label="评价内容">
          <el-input type="textarea" v-model="form.content"></el-input>
        </el-form-item>
<!--        <el-form-item label="是否展示在补发师详情，0 = 否，1 = 是" prop="isShow">-->
<!--          <el-input v-model="form.isShow" placeholder="请输入是否展示在补发师详情，0 = 否，1 = 是" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="类型" prop="type">-->
<!--          <el-select v-model="type" placeholder="请选择" @change="uploadTypeChanged">-->
<!--            <el-option-->
<!--              v-for="dict in banner_type"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="评价图片" prop="evaluationPicture">
        <image-uploads v-model="form.evaluationPicture"></image-uploads>
        </el-form-item>
        <el-form-item label="评价视频" prop="evaluationPicture">
          <video-upload v-model="form.evaluationPicture"></video-upload>
        </el-form-item>
        <el-form-item label="回复内容">
          <el-input type="textarea" v-model="form.replyContent"></el-input>
        </el-form-item>
        <el-form-item label="是否显示在补发师详情" prop="isShow" label-width="170">
          <el-radio-group v-model="form.isShow">
            <el-radio
              v-for="dict in sys_show_status"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="显示状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in sys_show_hide"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="HairTeacherEvaluate">
import { listHairTeacherEvaluate,topEvaluate, getHairTeacherEvaluate, delHairTeacherEvaluate, addHairTeacherEvaluate, updateHairTeacherEvaluate } from "@/api/business/hairTeacherEvaluate";
import {useRoute, useRouter} from 'vue-router';
const router = useRouter();
import ImageUploads from "@/components/ImageUploads/index.vue";
import VideoUpload from "@/components/VideoUpload/index.vue";
import {
  listHairFixTeacher
} from "@/api/business/hairFixTeacher";
import {
  listHairFixShop
} from "@/api/business/hairFixShop";
const route = useRoute()
const { proxy } = getCurrentInstance();
const { sys_show_status,sys_show_hide, sys_normal_disable,banner_type,belong_military_region } =
  proxy.useDict("sys_show_status","sys_show_hide", "sys_normal_disable","banner_type","belong_military_region");
const hairTeacherEvaluateList = ref([]);
const hairFixShopList = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const type = ref("");
const hairFixTeacherList = ref([]); //补发师列表
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    teacherId:  route.query != undefined ? route.query?.teacherId : undefined,
    userId: undefined,
    nickName: undefined,
    avatar: undefined,
    overallScore: undefined,
    serveScore: undefined,
    mannerScore: undefined,
    effectScore: undefined,
    content: undefined,
    isShow: undefined,
    evaluationPicture: undefined,
  },
  rules: {
    id: [
      { required: true, message: "主键id不能为空", trigger: "blur" }
    ],
    teacherId: [
      { required: true, message: "补发师id不能为空", trigger: "blur" }
    ],
    userId: [
      { required: true, message: "用户id不能为空", trigger: "blur" }
    ],
    nickName: [
      { required: true, message: "昵称不能为空", trigger: "blur" }
    ],
    avatar: [
      { required: true, message: "用户头像不能为空", trigger: "blur" }
    ],
    overallScore: [
      { required: true, message: "总体评分不能为空", trigger: "blur" }
    ],
    serveScore: [
      { required: true, message: "服务分数不能为空", trigger: "blur" }
    ],
    mannerScore: [
      { required: true, message: "态度分数不能为空", trigger: "blur" }
    ],
    effectScore: [
      { required: true, message: "效果分数不能为空", trigger: "blur" }
    ],
    content: [
      { required: true, message: "评价内容不能为空", trigger: "blur" }
    ],
    isShow: [
      { required: true, message: "是否展示在补发师详情，0 = 否，1 = 是不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询补发师评价信息列表 */
function getList() {
  loading.value = true;
  listHairTeacherEvaluate(queryParams.value).then(response => {
    hairTeacherEvaluateList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 查询补发师信息列表 */
/** 查询补发师信息列表 */
function getTeacherList(theirMilitary,shopId) {
  listHairFixTeacher({
    pageNum: 1,
    pageSize: 999999,
    theirMilitary: theirMilitary,
    shopId:shopId
  }).then((response) => {
    hairFixTeacherList.value = response.rows;
  });
}
function getShopList(theirMilitary) {
  listHairFixShop({
    pageNum: 1,
    pageSize: 999999,
    theirMilitary: theirMilitary}).then((response) => {
    hairFixShopList.value = response.rows;
  });
}
getShopList();
getTeacherList();
function selectTheirMilitary(row){
  getShopList(row)
  getTeacherList(row)
  form.value.shopId = null;
  form.value.teacherId = null;
}

function selectShop(row){
  getTeacherList("",row)
  form.value.teacherId = null;
}
// 取消按钮
function cancel() {
  open.value = false;
  reset();
  getShopList();
  getTeacherList();
}

/** 评价置顶状态修改  */
function handleStatusChange(row) {
  console.log(row)
  let text = row.isTop === "0" ? "取消置顶" : "置顶";
  proxy.$modal.confirm('确认要"' + text + '吗').then(function () {
    return topEvaluate({id: row.id, teacherId: row.teacherId});
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess(text + "成功");
  }).catch(function () {
    row.isTop = row.isTop === "0" ? "1" : "0";
  });
};

// 表单重置
function reset() {
  form.value = {
    id: null,
    teacherId: null,
    userId: null,
    nickName: null,
    avatar: null,
    overallScore: null,
    serveScore: null,
    mannerScore: null,
    effectScore: null,
    content: null,
    isShow: "1",
    evaluationPicture: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    delFlag: null
  };
  proxy.resetForm("hairTeacherEvaluateRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  router.push({query: {},});
  queryParams.value.teacherId = undefined;
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加补发师评价信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  loading.value = true
  reset();
  const _id = row.id || ids.value
  getHairTeacherEvaluate(_id).then(response => {
    loading.value = false;
    form.value = response.data;
    open.value = true;
    title.value = "修改补发师评价信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["hairTeacherEvaluateRef"].validate(valid => {
    if (valid) {
      buttonLoading.value = true;

      if (form.value.id != null) {
        updateHairTeacherEvaluate(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        }).finally(() => {
          buttonLoading.value = false;
        });
      } else {
        addHairTeacherEvaluate(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        }).finally(() => {
          buttonLoading.value = false;
        });
      }
    }
  });
}



/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除补发师评价信息编号为"' + _ids + '"的数据项？').then(function() {
    loading.value = true;
    return delHairTeacherEvaluate(_ids);
  }).then(() => {
    loading.value = true;
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  }).finally(() => {
    loading.value = false;
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('business/hairTeacherEvaluate/export', {
    ...queryParams.value
  }, `hairTeacherEvaluate_${new Date().getTime()}.xlsx`)
}

getList();
</script>
